package com.example.demo.mapper;

import com.example.demo.entity.Info;
import com.example.demo.entity.Report;
import com.example.demo.entity.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface AdminMapper {

    //查看所有举报信息
    @Select("select id, title, username, kind, phone, rights, orientation, price, joint, lease, requirement, furniture, floor, type, area, elevator, decoration, location, picture, other, date from info where exists (select id from report where report.info_id=info.id)")
    List<Info> findAllReport();

    //查看一条举报信息
    @Select("select id, title, username, kind, phone, rights, orientation, price, joint, lease, requirement, furniture, floor, type, area, elevator, decoration, location, picture, other, date from info where exists (select id from report where report.info_id=info.id and info.id=#{id})")
    Info findAReportInfo(int id);

    @Delete("delete from report where info_id=#{id}")
    int deleteAReport(int id);

    //查看一条举报信息的内容
    @Select("select content, date from report where info_id=#{id}")
    Report findAReportContent(int id);

    //删除违规信息
    @Delete("delete from Info where id=#{id}")
    int deleteAInfo(int id);

    //封禁违规用户
    @Update("update users set banned=true where username=#{username2}")
    int bannedUser(String username2);

    //解封违规用户
    @Update("update users set banned=false where username=#{username2}")
    int unbannedUser(String username2);

    //返回所有未封禁用户
    @Select("select username, banned from users where banned=false and admin=false")
    List<User> findAllUnban();

    //返回所有已封禁用户
    @Select("select * from users where banned=true and admin=false")
    List<User> findAllBan();
}
